package com.notetool.gui;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTable;
import java.awt.Dimension;
import javax.swing.border.BevelBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import java.awt.Font;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;

import com.notetool.dataprovider.NoteDataProvider;
import com.notetool.util.ParsingHelper;
import com.notetool.util.config.AppConfig;
import com.notetool.util.config.ConfigSet;
import com.notetool.util.tokenparser.Parser;
import com.notetool.util.tokenparser.TokenList;

import java.awt.Rectangle;

public class FrmNoteTool extends JFrame
{

    ////////////////////
    // Members
	private JPanel contentPane;
	private JTextField textField;
	private JTable table;
	private JTextField textField_1;
	private JTextField textField_2;
	
	////////////////////
	// Static init
	static
	{
	    try
	    {
            // Set Windows look and feel
	        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	    } 
	    catch (Exception ex)
	    {
	        ex.printStackTrace();
	    }
	}
	
	////////////////////
	// Main
    public static void main(String[] args)
    {
        Parser pars = ParsingHelper.getTestParser ();
        try
        {
            
            TokenList list = pars.getTokens(" ff &  (@h) | @\"fdfd\\\" \" & h  ");
            list.purge("whiteSpace");
            list.print(System.out);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        //  Create and display Window through the event thread...
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    FrmNoteTool frame = new FrmNoteTool();
                    frame.setVisible(true);
                    NoteDataProvider provider = NoteDataProvider.getDataProvider ();
                   // provider.getNotes();
                } 
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });
    }
    
	
	public FrmNoteTool() 
	{
	    // All of this should definitely be in its own method, but the editor puts it right there...
	    // So just deal with it, I know it's ugly as hell.
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 514, 362);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0};
		gbl_contentPane.rowHeights = new int[]{0};
		gbl_contentPane.columnWeights = new double[]{0.0};
		gbl_contentPane.rowWeights = new double[]{0.0};
		contentPane.setLayout(gbl_contentPane);
		
		JPanel mainPanel = new JPanel();
		mainPanel.setPreferredSize(new Dimension(0, 0));
		mainPanel.setMinimumSize(new Dimension(0, 0));
		GridBagConstraints gbc_mainPanel = new GridBagConstraints();
		gbc_mainPanel.fill = GridBagConstraints.BOTH;
		gbc_mainPanel.weighty = 1.0;
		gbc_mainPanel.weightx = 1.0;
		gbc_mainPanel.gridx = 0;
		gbc_mainPanel.gridy = 0;
		contentPane.add(mainPanel, gbc_mainPanel);
		GridBagLayout gbl_mainPanel = new GridBagLayout();
		gbl_mainPanel.columnWidths = new int[]{0};
		gbl_mainPanel.rowHeights = new int[]{0, 0};
		gbl_mainPanel.columnWeights = new double[]{0.0};
		gbl_mainPanel.rowWeights = new double[]{0.0, 0.0};
		mainPanel.setLayout(gbl_mainPanel);
		
		JPanel contentPanel = new JPanel();
		contentPanel.setMinimumSize(new Dimension(0, 0));
		contentPanel.setPreferredSize(new Dimension(0, 0));
		GridBagConstraints gbc_contentPanel = new GridBagConstraints();
		gbc_contentPanel.weighty = 1.0;
		gbc_contentPanel.weightx = 1.0;
		gbc_contentPanel.fill = GridBagConstraints.BOTH;
		gbc_contentPanel.insets = new Insets(0, 0, 0, 0);
		gbc_contentPanel.gridx = 0;
		gbc_contentPanel.gridy = 0;
		mainPanel.add(contentPanel, gbc_contentPanel);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{0, 0};
		gbl_contentPanel.rowHeights = new int[]{0, 0};
		gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setMinimumSize(new Dimension(0, 0));
		tabbedPane.setPreferredSize(new Dimension(0, 0));
		GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
		gbc_tabbedPane.weighty = 1.0;
		gbc_tabbedPane.weightx = 1.0;
		gbc_tabbedPane.fill = GridBagConstraints.BOTH;
		gbc_tabbedPane.gridx = 0;
		gbc_tabbedPane.gridy = 0;
		contentPanel.add(tabbedPane, gbc_tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("Notes", null, panel, null);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{0, 0};
		gbl_panel.rowHeights = new int[]{0, 0};
		gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.5);
		splitPane.setMinimumSize(new Dimension(0, 0));
		splitPane.setPreferredSize(new Dimension(0, 0));
		GridBagConstraints gbc_splitPane = new GridBagConstraints();
		gbc_splitPane.weighty = 1.0;
		gbc_splitPane.weightx = 1.0;
		gbc_splitPane.fill = GridBagConstraints.BOTH;
		gbc_splitPane.gridx = 0;
		gbc_splitPane.gridy = 0;
		panel.add(splitPane, gbc_splitPane);
		
		JPanel panel_2 = new JPanel();
		panel_2.setMinimumSize(new Dimension(0, 0));
		panel_2.setPreferredSize(new Dimension(0, 0));
		splitPane.setLeftComponent(panel_2);
		GridBagLayout gbl_panel_2 = new GridBagLayout();
		gbl_panel_2.columnWidths = new int[]{0};
		gbl_panel_2.rowHeights = new int[]{0, 0};
		gbl_panel_2.columnWeights = new double[]{1.0};
		gbl_panel_2.rowWeights = new double[]{0.0, 1.0};
		panel_2.setLayout(gbl_panel_2);
		
		textField = new JTextField();
		textField.setFont(new Font("Courier New", Font.PLAIN, 11));
		textField.setBorder(new CompoundBorder(new LineBorder(new Color(0, 0, 0)), new EmptyBorder(0, 2, 0, 2)));
		textField.setPreferredSize(new Dimension(0, 20));
		textField.setMinimumSize(new Dimension(0, 0));
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.weightx = 1.0;
		gbc_textField.insets = new Insets(2, 2, 2, 2);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 0;
		gbc_textField.gridy = 0;
		panel_2.add(textField, gbc_textField);
		textField.setColumns(10);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setBorder(new LineBorder(new Color(0, 0, 0)));
		scrollPane.setPreferredSize(new Dimension(0, 0));
		scrollPane.setMinimumSize(new Dimension(0, 0));
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.insets = new Insets(0, 2, 2, 2);
		gbc_scrollPane.weighty = 1.0;
		gbc_scrollPane.weightx = 1.0;
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 1;
		panel_2.add(scrollPane, gbc_scrollPane);
		
		table = new JTable();
		table.setBorder(null);
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				null, null, null, null
			}
		));
		scrollPane.setViewportView(table);
		
		JPanel panel_3 = new JPanel();
		panel_3.setMinimumSize(new Dimension(0, 0));
		panel_3.setPreferredSize(new Dimension(0, 0));
		splitPane.setRightComponent(panel_3);
		GridBagLayout gbl_panel_3 = new GridBagLayout();
		gbl_panel_3.columnWidths = new int[]{0};
		gbl_panel_3.rowHeights = new int[]{0, 0, 0, 0};
		gbl_panel_3.columnWeights = new double[]{0};
		gbl_panel_3.rowWeights = new double[]{0, 0, 0, 0};
		panel_3.setLayout(gbl_panel_3);
		
		JPanel panel_4 = new JPanel();
		panel_4.setPreferredSize(new Dimension(0, 30));
		panel_4.setMinimumSize(new Dimension(0, 0));
		GridBagConstraints gbc_panel_4 = new GridBagConstraints();
		gbc_panel_4.weightx = 1.0;
		gbc_panel_4.insets = new Insets(0, 0, 2, 0);
		gbc_panel_4.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_4.gridx = 0;
		gbc_panel_4.gridy = 0;
		panel_3.add(panel_4, gbc_panel_4);
		GridBagLayout gbl_panel_4 = new GridBagLayout();
		gbl_panel_4.columnWidths = new int[]{0, 0};
		gbl_panel_4.rowHeights = new int[]{0};
		gbl_panel_4.columnWeights = new double[]{0.0, 0};
		gbl_panel_4.rowWeights = new double[]{0.0};
		panel_4.setLayout(gbl_panel_4);
		
		JLabel lblId = new JLabel("Id :");
		lblId.setMaximumSize(new Dimension(35, 14));
		lblId.setMinimumSize(new Dimension(35, 14));
		lblId.setPreferredSize(new Dimension(35, 14));
		lblId.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblId = new GridBagConstraints();
		gbc_lblId.insets = new Insets(0, 0, 0, 5);
		gbc_lblId.anchor = GridBagConstraints.WEST;
		gbc_lblId.gridx = 0;
		gbc_lblId.gridy = 0;
		panel_4.add(lblId, gbc_lblId);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("Courier New", Font.PLAIN, 11));
		Border rounded = new LineBorder(new Color(0,0,0));
		Border empty = new EmptyBorder(0, 1, 0, 1);
		
		Border border = new CompoundBorder(rounded, empty);
		textField_1.setBorder(new CompoundBorder(new LineBorder(new Color(0, 0, 0)), new EmptyBorder(0, 2, 0, 2)));
		//textField_1.setBorder(new LineBorder(new Color(0, 0, 0)));
		textField_1.setPreferredSize(new Dimension(0, 20));
		textField_1.setMinimumSize(new Dimension(0, 20));
		GridBagConstraints gbc_textField_1 = new GridBagConstraints();
		gbc_textField_1.insets = new Insets(0, 0, 0, 5);
		gbc_textField_1.weightx = 1.0;
		gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_1.gridx = 1;
		gbc_textField_1.gridy = 0;
		panel_4.add(textField_1, gbc_textField_1);
		textField_1.setColumns(10);
		
		JPanel panel_5 = new JPanel();
		GridBagConstraints gbc_panel_5 = new GridBagConstraints();
		gbc_panel_5.weightx = 1.0;
		gbc_panel_5.insets = new Insets(0, 0, 5, 0);
		gbc_panel_5.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_5.gridx = 0;
		gbc_panel_5.gridy = 1;
		panel_3.add(panel_5, gbc_panel_5);
		GridBagLayout gbl_panel_5 = new GridBagLayout();
		gbl_panel_5.columnWidths = new int[]{0, 0, 0};
		gbl_panel_5.rowHeights = new int[]{0, 0};
		gbl_panel_5.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		gbl_panel_5.rowWeights = new double[]{0.0, Double.MIN_VALUE};
		panel_5.setLayout(gbl_panel_5);
		
		JLabel lblTags = new JLabel("Tags :");
		lblTags.setPreferredSize(new Dimension(35, 14));
		lblTags.setMinimumSize(new Dimension(35, 14));
		lblTags.setMaximumSize(new Dimension(35, 14));
		lblTags.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblTags = new GridBagConstraints();
		gbc_lblTags.insets = new Insets(0, 0, 0, 5);
		gbc_lblTags.anchor = GridBagConstraints.EAST;
		gbc_lblTags.gridx = 0;
		gbc_lblTags.gridy = 0;
		panel_5.add(lblTags, gbc_lblTags);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("Courier New", Font.PLAIN, 11));
		textField_2.setBorder(new CompoundBorder(new LineBorder(new Color(0, 0, 0)), new EmptyBorder(0, 2, 0, 2)));
		textField_2.setPreferredSize(new Dimension(0, 20));
		textField_2.setMinimumSize(new Dimension(0, 20));
		textField_2.setColumns(10);
		GridBagConstraints gbc_textField_2 = new GridBagConstraints();
		gbc_textField_2.insets = new Insets(0, 0, 0, 5);
		gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_2.gridx = 1;
		gbc_textField_2.gridy = 0;
		panel_5.add(textField_2, gbc_textField_2);
		
		JPanel panel_6 = new JPanel();
		panel_6.setMinimumSize(new Dimension(0, 0));
		panel_6.setPreferredSize(new Dimension(0, 0));
		GridBagConstraints gbc_panel_6 = new GridBagConstraints();
		gbc_panel_6.weighty = 1.0;
		gbc_panel_6.weightx = 1.0;
		gbc_panel_6.insets = new Insets(0, 0, 5, 0);
		gbc_panel_6.fill = GridBagConstraints.BOTH;
		gbc_panel_6.gridx = 0;
		gbc_panel_6.gridy = 2;
		panel_3.add(panel_6, gbc_panel_6);
		GridBagLayout gbl_panel_6 = new GridBagLayout();
		gbl_panel_6.columnWidths = new int[]{0, 0};
		gbl_panel_6.rowHeights = new int[]{0, 0};
		gbl_panel_6.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_panel_6.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		panel_6.setLayout(gbl_panel_6);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBorder(new LineBorder(new Color(0, 0, 0)));
		GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
		gbc_scrollPane_1.insets = new Insets(0, 5, 0, 5);
		gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
		gbc_scrollPane_1.gridx = 0;
		gbc_scrollPane_1.gridy = 0;
		panel_6.add(scrollPane_1, gbc_scrollPane_1);
		
		JTextArea textArea = new JTextArea();
		textArea.setBorder(null);
		textArea.setFont(new Font("Courier New", Font.PLAIN, 13));
		scrollPane_1.setViewportView(textArea);
		
		JPanel panel_7 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_7.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		panel_7.setMinimumSize(new Dimension(0, 0));
		panel_7.setPreferredSize(new Dimension(0, 42));
		GridBagConstraints gbc_panel_7 = new GridBagConstraints();
		gbc_panel_7.weightx = 1.0;
		gbc_panel_7.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_7.gridx = 0;
		gbc_panel_7.gridy = 3;
		panel_3.add(panel_7, gbc_panel_7);
		
		JButton btnOk = new JButton("");
		btnOk.setEnabled(false);
		btnOk.setBorder(new LineBorder(new Color(0, 0, 0)));
		btnOk.setPreferredSize(new Dimension(33, 33));
		btnOk.setIcon(new ImageIcon("C:\\Users\\Ben\\Desktop\\Ben's Site\\check.png"));
		panel_7.add(btnOk);
		
		JButton btnCan = new JButton("");
		btnCan.setEnabled(false);
		btnCan.setBorder(new LineBorder(new Color(0, 0, 0)));
		btnCan.setPreferredSize(new Dimension(33, 33));
		btnCan.setIcon(new ImageIcon("C:\\Users\\Ben\\Desktop\\Ben's Site\\cancel.png"));
		panel_7.add(btnCan);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("Tools", null, panel_1, null);
		tabbedPane.setEnabledAt(1, false);
		
		JPanel bottomPanel = new JPanel();
		bottomPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		bottomPanel.setPreferredSize(new Dimension(0, 25));
		bottomPanel.setMinimumSize(new Dimension(0, 0));
		GridBagConstraints gbc_bottomPanel = new GridBagConstraints();
		gbc_bottomPanel.weightx = 1.0;
		gbc_bottomPanel.fill = GridBagConstraints.BOTH;
		gbc_bottomPanel.gridx = 0;
		gbc_bottomPanel.gridy = 1;
		mainPanel.add(bottomPanel, gbc_bottomPanel);
		
		
		textField.getDocument().addDocumentListener(new DocumentListener() {
		    public void changedUpdate(DocumentEvent e) {
		      //warn();
		    }
		    public void removeUpdate(DocumentEvent e) {
		      warn();
		    }
		    public void insertUpdate(DocumentEvent e) {
		      warn();
		    }

		    public void warn() {
		       try
		       {
		           ParsingHelper.getTestParser ().getTokens(textField.getText ());
		           textField.setBackground(Color.WHITE);
		           
		       }
		       catch (Exception ex)
		       {
		           textField.setBackground(Color.RED);
		       }
		    }
		  });

	}
}
